package game.adm.struts.action;

import game.adm.controller.ConfigInitController;
import game.adm.dao.dto.ConfigDTO;
import game.adm.struts.form.ConfigForm;
import game.adm.viewhelper.ConfigViewHelper;
import game.web.base.Constants;
import game.web.base.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import projectx.util.ClassUtil;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXForm;
import projectx.web.base.ProjectXSecurityAction;
import projectx.web.base.UserContext;
import projectx.web.base.navi.Function;

public class ConfigInitAction extends ProjectXSecurityAction {

	@Override
	protected boolean isPostMethodOnly() {
		return false;
	}

	@Override
	protected ActionForward execute(User user, Function function,
			ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		UserContext uc = getUc();
		ConfigForm configForm = (ConfigForm) form;
		configForm.setCofigid("1");
		ConfigInitController.execute(uc, (ProjectXForm) form);
		ConfigDTO dto = (ConfigDTO)uc.get(Constants.ADM_CONFIG_RECORD);

		if(dto==null)
			dto = new ConfigDTO();
		
		ConfigViewHelper viewHelper = new ConfigViewHelper(dto.getCofigid(),dto.getWebsitename(),dto.getHelplink(),dto.getUserscale(),user);
		//ClassUtil.copyData(dto, viewHelper);
		System.err.println("viewHelper="+viewHelper);
		request.setAttribute(ConstantsProjectX.VIEW_HELPER, viewHelper);
		debugEnd();
		return findForward(mapping, forwardSuccess);
	}
	
}
